﻿// -----------------------------------------------------------------------
// <copyright file="StringHelpers.cs" company="Eli Lilly and Company">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace ODataRegression.Framework.Core.Shared
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml;
    using System.Reflection;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class StringHelpers
    {
        public static string ExecuteStringFunctionViaReflection(XmlNode item, string inputString)
        {
            object[] paramaters;
            string find = string.Empty;
            string replace = string.Empty;
            string stringFunction;
            string url = inputString;
            Type stringType = typeof(string);


            if (item.NodeType == XmlNodeType.Element)
            {
                paramaters = new object[item.Attributes.Count];
                for (int i = 0; i < item.Attributes.Count; i++)
                {
                    paramaters[i] = item.Attributes[i].Value;
                }

                stringFunction = item.LocalName;
                url = (string)stringType.InvokeMember(stringFunction, BindingFlags.InvokeMethod |
                BindingFlags.Instance | BindingFlags.Public, null, url, paramaters);
            }
            return url;
        }
    }
}
